#region Copyright
/// <copyright>
/// Copyright (c) 2007 Ilia Shramko.
/// Released under the terms of the GNU General Public License.
/// </copyright>
#endregion

using System;
using System.Collections.Specialized;
using System.Text;

namespace Osh.Dvb
{
	/// <summary>
	/// Summary description for ExtendedEventDescriptor.
	/// </summary>
	public class ExtendedEventDescriptor : Descriptor
	{
		private LanguageCode _languageCode;
		private NameValueCollection _items;
		private string _text;
		private int _descriptorNumber;
		private int _lastDescriptorNumber;

		public ExtendedEventDescriptor(DescriptorReader reader, int length)
			: base(DescriptorTags.ExtendedEventDescriptor, length)
		{
			_descriptorNumber = _lastDescriptorNumber = reader.ReadByte();
			_descriptorNumber >>= 4;
			_lastDescriptorNumber &= 0xF;

			int languageCode = (int)reader.ReadUInt32BE();
			int eventItemsLength = languageCode & 0xFF;
			languageCode >>= 8;
			_languageCode = (LanguageCode)languageCode;

			_items = reader.ReadEventItems(eventItemsLength, _languageCode);

			int textLength = reader.ReadByte();
			_text = TextEncoding.Default.GetString(reader.ReadBytes(textLength), _languageCode);
		}

		public int DescriptorNumber
		{
			get { return _descriptorNumber; }
		}
		public int LastDescriptorNumber
		{
			get { return _lastDescriptorNumber; }
		}
		public LanguageCode LanguageCode
		{
			get { return _languageCode; }
		}
		public NameValueCollection Items
		{
			get { return _items; }
		}
		public string Text
		{
			get { return _text; }
		}
	}
}
